/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pfc.generacion;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 *
 * @author xandru
 */
class HTMLTag {
    String _tag;
    Properties _atributos = new Properties();
    List<String> _text= new ArrayList<String>();
    ArrayList<HTMLTag> _children = new ArrayList<HTMLTag>();
    ArrayList<String> _jspCode = new ArrayList<String>();

    HTMLTag (String tag)
    {
        _tag = tag;
    }

     private HTMLTag addTag(String string) {
        HTMLTag tmp = new HTMLTag(string);
        _children.add(tmp);
        return tmp;
    }

    HTMLTag addHead() {
        return addTag("head");

    }

    HTMLTag addBody() {
        return addTag("body");
    }

    HTMLTag addForm(String name, String method, String action) {
        HTMLTag form = addTag("form");
        form.addAttribute("name", name);
        form.addAttribute("method", method);
        form.addAttribute("action", action);
        return form;
    }

    HTMLTag addTable() {
        return addTag("table");
    }

    HTMLTag addTableRow() {
        return addTag("tr");
    }

    HTMLTag addTableData() {
        return addTag("td");
    }

    void addText(String string) {
        _text.add(string);
    }

    HTMLTag addInput(String type, String name, String value) {
        HTMLTag input = addTag("input");
        input.addAttribute("type", type);
        input.addAttribute("name", name);
        input.addAttribute("value", value);
        return input;
    }

    void addAttribute(String key, String value) {
         _atributos.setProperty(key, value);
    }

    Properties getAttributes() {
        return this._atributos;
    }

    boolean hasChildren() {
        return !this._children.isEmpty();
    }

    Iterable<HTMLTag> getChildrens() {
        return this._children;
    }

    String getTag() {
        return this._tag;
    }

    List<String> getText() {
        return this._text;
    }

    void addJspCode(String string) {
       _jspCode.add(string);
    }

    ArrayList<String> getJspCode() {
        return _jspCode;
    }

    HTMLTag addTableHeader() {
        return addTag("th");
    }


}
